package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.ArticleConstants;
import com.heima.search.service.ArticleSearchService;
import com.heima.search.vos.SearchArticleVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.avro.data.Json;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class EsSyncConsumer {

    @Autowired
    private ArticleSearchService articleSearchService;

    /**
     * 监听文章微服务发布文章 同步至es的消息
     *
     * @param msg 监听的消息
     */
    @KafkaListener(topics = ArticleConstants.ARTICLE_ES_SYNC_TOPIC)
    public void onMessage(String message) {
        if (StringUtils.isEmpty(message)) {
            return;
        }
        log.info("监听到文章微服务发布文章 同步至es的消息" + message);
        //同步至es中
        articleSearchService.esSync(message);
    }

}
